<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="../static/css/prism.css" rel="stylesheet" />
</head>

<body>
    <h2>reverse() 数组反转</h2>
    <p><strong>原地修改</strong></p>
    <pre><code class="language-javascript">var a = ['a', 'b', 'c'];

a.reverse() // ["c", "b", "a"]
a // ["c", "b", "a"]</code></pre>

    <p>案例：字符串反转（借助数组完成）</p>
    <pre><code class="language-javascript">var str = "hello";
str.split("").reverse().join("")
// split() 转为数组
// reverse() 原地修改数组
// join() 转为字符串
console.log(str);  // hello
console.log(str_new);  // olleh</code></pre>

    <script src="../static/js/prism.min.js"></script>

    <script>
        var str = "hello";
        var str_new = str.split("").reverse().join("");
        // split() 转为数组
        // reverse() 原地修改数组
        // join() 转为字符串
        console.log(str);
        console.log(str_new);
    </script>
</body>

</html>